package com.basker.pisces.sequence.config;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import com.basker.pisces.core.sequence.ILongSequrenceGenerator;
import com.basker.pisces.core.sequence.SnowFlakeSequrenceGenerator;

@Configuration
public class SnowflakeSequenceGeneratorConfiguration {

    @Bean
    @ConditionalOnMissingBean(ILongSequrenceGenerator.class)
    public SnowFlakeSequrenceGenerator snowFlakeSequrenceGenerator(
            @Value("${pisces.snowflake.workerId:0}") int workerId,
            @Value("${pisces.snowflake.datacenterId:0}") int datacenterId) {
        return new SnowFlakeSequrenceGenerator(workerId, datacenterId);
    }
}
